Removed code duplication with some macro help, turned out it also helped to reduce dependencies