writing functions for the implementation