cleaned up, added type safety