code format and specs rewritten