Fixed bugs. Final version!