Refactor, cleanup some logic

Was reading through the file and cleaned up a few things on the way