fixed bugs + automatically move cursor to beginning