Committing current work. It sort of works, but still needs debugging.