Pure python implementation