start/end added for reading and bug fixed for sam input