Fixes and additional stuff from Pavlos. NOT SURE IF THIS IS WORKING!