another big refactor commit - use promises properly