fix minor stackoverflow bug
remove unnecessary files
fix off-by-one error