cleanup code and added some doctags