ref #10 - erased the warnings with some casting and refactoring.