re-organized files and fixed some bugs