fixed some bugs in it and modified some code to work more simple