fixed recent regression + simplified code a bit