misc optimization and clean up

problem with one letter variables is that i don't know what they mean.
what is ```p```? can you rename it?