Improved design
Added some error handlings