Some compilation and bug fixes