quick fix - restored some code from stable version 6b07d2c