fixed parse-input to handle loop substring properly
got rid of end-loop function because it is unecessary. parse-input seems to work properly now.