change fn's names
add boundary check. still buggy