fixed a few bugs, more or less done now.