Added Promise type. Improved code