Reworked code and updated ai