a lot of work and bug fixes

Signed-off-by: cout970 <thecout970@gmail.com>