Change to return python object instead, as it simplifies memory management and it gets rid of more locking