Implemented many-to-many logic and fixed several small bugs throughout