smoothed movement out and cleaned up code