Fix DST code and add unit tests