Refined implementation and added functionality