Fix #207, perormance improvements