fix important and nasty bug + added test