Fixed small bugs for final implementation