Good chunk of slinkio/plockity#13 rewrite