Functional!

need to fine tune, but should work