some bugs corrected... still not working perfectly