updated codes
'fixed'
updated with more refactoring