Final code for AI lab