cleanup
prevented unnecessary nesting
new version