better implementation, Fixes #42 again