Code optimization, bugfixes.