added more logic, but contains le bugz