copied changes from denschu's repository