fixed code to a working state