Refactor

There are bugs in this version