class cleanup, fixed bug with replacement
slightly better tests