misc programming and some bugs for future corrections