Refactor for readability and functionalize coordinate input