updated code and writeup