fixed some bugs + fixed output