refactored into two different files, added logging support