restructure bot code