Refactor get_commit method