misc refinement, indentation, separate files