cleanup, adding documentation
rearranging code
minor cleanup