code simplification and cleanup