The short answer is to read your employment, consultant or partnership contract (the "loose agreement"). If that's not clear then show it to a lawyer.
General guidelines for the US are that "work for hire" is owned by the employer (whether explicitely assigned in the employment agreement or not!). Other types of relationships (e.g. partnerships, consulting, etc.) only transfer ownership of IP to the company if the contract explicitely says so.
At the end of the day that's all that matters: what was your legal relationship with the company and what did you sign. Writing code, working hard, being kept in the loop, etc. has no relevance at all. So the long answer also boils down to "read your contract". Sorry.