Modifications to the code. Working version