optimize code a little bit