Some bug fixes, still buggy