added log file, bug fixes, refactored