Some fixes, although still not perfect