Numerous bugfixes, some tweaks to subroutinedec.