Refactored to implement sql queries and button functionality.