added better implementation for related functions