core refactor of angular, some safety fixes