added flash error and merged function into SM