renamed win -> window
made more variable names clear
clarified comment
indin -> index_in
clarified more variables