Implemented stage dependencies and fixed many issues with types.