Some syntax and efficiency fixes