cleaning up and improving code