added main to test the implementation and fixed some bugs