Make few fixes and cleanup the code