reworked for cleaner code