final ver. for code