Updated to match gist with simplifications