clean up and improve code