Calling preventDefault and some refactoring.