Added code documentation and some cleanup