Refactored lots of functions and added click listener for remove button.