updates to the logic and a few fixes