Added SEM + cleaned code