some logic changes / bug fixes