improved previous/next button implementation for form to make it more robust