Fix #3, another small bug and a performance issue