Cleaned up final code