Various fixes, new functions