Improved logging function with timestamp and a bunch of other tweaks