Working code

Converted code to working state.