Added logging and improved encapsulation