Working version

First complete version. Still ugly.