added out of bounds exception for k