Fixed bug when removing a test from a page the pages would still be linked in the edit and detail pages of that test, refactored some code