replaced master branch with current ugly, working code