Introduced procedures; some bugfixes