Add Api and DataHandler. Fix several bugs