cleaned up and documented