fixed index out of bounds exception
general cleanup