Finished functional version. Requires bugfixing.