Sam

refactored and updateed core functions