Fix bugs in implentation and add solution