optimized code a little bit