Suggestions from manolama resulted in less and cleaner code