Re-organised the code to differentiate between main and playpen