fixed bug with moving back and forward
refactored