Cleaned up, implemented logging