Various fixes and new functions.