update to latest code

also refactored code to package 'formative'