Refreshed code and bug-fixes.

Not the final version, functionality missing.