More bug fixes - better logic