Cleanup code and fix some bugs found while trying to use create PR command (talk about dogfooding!)