added a macro and made the partition function cleaner