fixed bugs and finished main parts