Converted the last commands to scala. The 2 i skipped are way to messy and broken to even bother about