fixed up logic problems