Fixed log function, general bugfixing