Various fixes and sync with original project