Code cleanup + smal fixes