Fixed error code and testing promises and referred functions