Refatoring, fixes