refactired accirding to the API and the coding conventions