Updated and encapsuled the api