Clean up ugly code