restructured into methods, incomplete