rewrite library to make it simpler