refactored readfile and nested promises