Finalised python3 re-write