Updated the code to be a lot better. removed code smells.