new patterns + modularize the source + add unit testing