small optimizations
working solution