Refactored some code to hopefully pass webcat