Cleaned up logic and code