mostly refactored for Angular