Changed implementation due to problems with destroyed elements