fixing defects, code clean up