basic working code, needs tests and docs