Refactored basic code, general clean ups and beginning of log implementation.