Various bugfixes. Functions not working yet.