improved code a little