fixed and cleaned script