Cleaned up swap and dup, which had unnecessary code duplication