Fixed building issues and improve entity API.