Cleaned up bot code and added error checking