basic code

Still some bugs but good enough to start testing.