basic
optimized code and fixed some bugs