Added commit checkout method and made code more robust