Initial conversion of most code to scala