optimized code a bit