code reorganised. fixing errors
code reorganised. fixing errors