Fixed implementation

Still not sure if it's doing everything right. But
I'll live with this for now.