added some nicer comments and cleaned up