Moved some code around and changed some names