trying to make the go function a little more readable. probably not succeeding.
Added some documentation.