Code cleanup + add dox