fixed all logic to be a bit more efficient