Use python functions instead of shell pipes

This is just a tiny bit faster.