Cleaned some code and logic