Remade the basic code

Remade the basic code and fixed some bugs