Made more generic, should be usable with own types.