Simplified the expansion code a bit