some cleanup and simplification