Added log functionality
Various fixes