Tested code

Tested and fixed code