Fixing issue #30 and done a little refactoring...