Code cleanup and improved logging

Moved version to 0.4.0