restructured code + added a simple logger