Almost copy-pasted this. Had to modify some imports though