Fixed infinite loop issue, started to add database support