Moved around code and fixed test