Fixed silly bugs. Code is now in working state.