final code cleaned up