Move previous commit code to inside try-except block