added bounds checking and smoother movement