Trivial reorganizaiton of code
Added comments on newly found bugs