Version 2

Simpler. will do it all in bash with no dependencies shortly.