adding success message and more refactoring