Added check to ensure :column_name provided by the user exists in the database and refactored code.