Fixed bot
Added logging function
removed some duplicate code