made core code more rust idomatic and more immuatable in relation to issue #4