Merged wrong and restored code with this commit