Updated, cleaned-up code.