rearenged code a litte bit