Various fixes and rework.