Initial commit. basically working. needs tests and minor improvements