Refactored version. refs #12 #13