Initial commit.

Untested version without sync check support.
First working version.

Fixed some minor bugs.