fixed minor boundary case bugs