basic refactoring & reformatting
add createElement function, simplify main code