improving code a bit