cleaned up final code