Roughly working version.

There are still a lot of hard-coded values, but after setting the proper values it should work.