refatored a little